package frist50;

import org.junit.jupiter.api.Test;

import java.util.Arrays;

public class T0006 {
    public String convert(String s, int numRows) {
        if(s.length()==1||numRows==1)return s;
        StringBuffer[] strs = new StringBuffer[numRows];
        for (int i = 0; i <numRows ; i++) {
            strs[i]=new StringBuffer();
        }
        for (int i = 0; i < s.length(); i += (2 * numRows - 2)) {
            System.out.println("$$"+strs[0]+" "+strs[1]+" "+strs[2]);
            for (int j = 0; j < numRows && i + j < s.length(); j++) {
                strs[j].append(s.charAt(i + j));
                System.out.println("--"+strs[0]+" "+strs[1]+" "+strs[2]);
            }
            for (int j = numRows - 2; j >= 1&& (2 * numRows - 2 - j + i) < s.length(); j--) {
                strs[j].append(s.charAt(2 * numRows - 2 - j + i));
                System.out.println("--"+strs[0]+" "+strs[1]+" "+strs[2]);
            }
        }
        String re = "";
        for (StringBuffer str : strs) {
            re = re + str;
        }
        return re;
    }

    @Test
    public void test() {

        System.out.println(convert("1234",3));
    }
}
